#ifndef __COMMON_DEF_H
#define __COMMON_DEF_H


typedef enum BOOL
{
    FALSE = 0,
    TRUE,
}BOOL_E;

typedef enum BOARD_TYPE
{
    BOARD_SLAVE,
    BOARD_MAIN,

}BOARD_TYPE_E;


typedef enum SYS_ERR
{
    SYS_OK = 0,
    SYS_NOK,
    SYS_ERR_CHECKSUM,
    SYS_ERR_PARAMETER,
    SYS_ERR_NOACK,
}SYS_ERR_E;

typedef enum DEV_STATUS
{
    DEV_INV = 0,
    DEV_INIT_FAIL,
    DEV_INIT_OK,
    DEV_READ_FAIL,
    DEV_READ_OK,
}DEV_STATUS_E;


#define   DATA_T_INV    (0)
#define   DATA_T_S      (1)
#define   DATA_T_C      (2)
#define   DATA_T_SC     (3)

#define     DATA_1B      (0)
#define     DATA_1C         (1)
#define     DATA_10C        (2)
#define     DATA_100C       (3)
#define     DATA_1000C      (4)

typedef BOOL_E (*pFunc)(void);
typedef void (*pvFunc)(void);
typedef BOOL_E (*pWFunc)(void* pMeter);
typedef void (*pTaskFunc)(void* pvParmeters);

typedef struct PROJ_DEV
{
    char name[12];
    BOOL_E useFlg;
    DEV_STATUS_E devStatus;
    pFunc read;
    pFunc init;
    pWFunc write;
}PROJ_DEV_S;

typedef struct PROJ_DATA
{
    char name[12];
    s16* data;
    u16 scType:2 ;
    u16 drVal:2 ;

}PROJ_DATA_S;

#define CFG_INCLUDE_DEV_WR(NAME)    {#NAME, FALSE, DEV_INV, NAME##_Read,   NAME##_Init,    NAME##_Write}
#define CFG_INCLUDE_DEV_W(NAME)     {#NAME, FALSE, DEV_INV, NULL,          NAME##_Init,    NAME##_Write}
#define CFG_INCLUDE_DEV_R(NAME)     {#NAME, FALSE, DEV_INV, NAME##_Read,   NAME##_Init,    NULL}
#define CFG_INCLUDE_DEV(NAME)       {#NAME, FALSE, DEV_INV, NULL,          NAME##_Init,    NULL}

#define CFG_USE_DEV(NAME)                                               \
    do                                                                  \
    {                                                                   \
        for (int i = 0; i < get_AllDevNum(); ++i)                       \
        {                                                               \
            if (strncmp(g_astProjAllDev[i].name, #NAME, strlen(#NAME)) == 0) \
            {                                                           \
                g_astProjAllDev[i].useFlg = TRUE;                       \
                break;                                                  \
            }                                                           \
        }                                                               \
    } while (0)

#define CFG_USE_DATA(NAME, type, dr)      {#NAME, &g_##NAME, DATA_T_##type, DATA_##dr}

   

#define checknum(err)\
    do\
    {\
        if(err != 0UL)\
        {\
            return SYS_ERR_PARAMETER;\
        }\
    }\
    while(0UL);

#define swab16(x)   (((((u16)x) & 0xFFU) << 8) | (((u16)x) >> 8))
#define swab32(x)   ( \
                     ((((u32)x) >> 24) & 0x000000FFU) | \
                     ((((u32)x) >>  8) & 0x0000FF00U) | \
                     ((((u32)x) <<  8) & 0x00FF0000U) | \
                     ((((u32)x) << 24) & 0xFF000000U) )


u32 simple_strtoul(const char *cp, char **endp, u32 base, u32 *err);
s32 simple_strtol(const char *cp, char **endp, u32 base);


#endif
